#!/usr/bin/perl -wc

package RFCMail::Log::Syslog;

use strict;
use Sys::Syslog;


my %LEVEL = qw(d debug i info n notice w warning e err c crit);


sub import {
    my ($class, %opts) = @_;
    my $ident = $opts{ident} || $0;
    my $facility = $opts{facility} || 'mail';
    openlog($ident, 'pid', $facility);
}


sub logmsg {
    my $self = shift;
    _syslog(@_)
	if not exists($self->{syslog_active}) or $self->{syslog_active};
    $self->SUPER::logmsg(@_);
}


sub hansard {
    my $self = shift;
    _syslog($self->{syslog_hansard}, @_)
	if $self->{syslog_hansard};
    $self->SUPER::hansard(@_);
}


sub _syslog {
    my $level = $LEVEL{shift()};
    for (@_) {
	eval { syslog($level, '%s', $_) };
    }
}


1;
